//
//  LEOrderDetialController.m
//  LoveExpressBusiness
//
//  Created by 刘甲奇 on 2017/5/12.
//  Copyright © 2017年 DFH. All rights reserved.
//

#import "LEOrderDetialController.h"
#import "LEOrderNumberCell.h"
#import "LEGoodsCell.h"
#import "LEOrderTimeCell.h"
#import "LEPayTypeCell.h"
#import "LEServieStaffCell.h"
#import "MakerTools.h"

#import "LESelectStaffController.h"

static NSString *const LEOrderNumberCellId = @"LEOrderNumberCell";
static NSString *const LEGoodsCellId = @"LEGoodsCell";
static NSString *const LEOrderTimeCellId = @"LEOrderTimeCell";
static NSString *const LEPayTypeCellId = @"LEPayTypeCell";
static NSString *const LEServieStaffCellId = @"LEServieStaffCell";

@interface LEOrderDetialController ()

@end

@implementation LEOrderDetialController

- (void)setupUI
{
    [super setupUI];
    self.title = @"订单详情";
    
    self.tableView.backgroundColor = LEBackgroundColor;
    [self.tableView registerNib:[UINib nibWithNibName:@"LEOrderNumberCell" bundle:nil] forCellReuseIdentifier:LEOrderNumberCellId];
    [self.tableView registerNib:[UINib nibWithNibName:@"LEGoodsCell" bundle:nil] forCellReuseIdentifier:LEGoodsCellId];
    [self.tableView registerNib:[UINib nibWithNibName:@"LEOrderTimeCell" bundle:nil] forCellReuseIdentifier:LEOrderTimeCellId];
    [self.tableView registerNib:[UINib nibWithNibName:@"LEPayTypeCell" bundle:nil] forCellReuseIdentifier:LEPayTypeCellId];
    [self.tableView registerNib:[UINib nibWithNibName:@"LEServieStaffCell" bundle:nil] forCellReuseIdentifier:LEServieStaffCellId];
    [self resetTablewFrame:CGRectMake(0, 0, LEScreenWidth, LEScreenHeight - 64)];
}

#pragma mark- tableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 4;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 1)
    {
        if (self.orderModel.goods)
        {
            return self.orderModel.goods.count;
        }else{
            return 1;
        }
    }
    if (section == 3)
    {
        if ([self.orderModel.door_service isEqualToString:@"1"])
        {
            //配送消费
            return 2;
        }else
        {
            //店内消费
            return 1;
        }
    }
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.01;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)
    {
       LEOrderNumberCell *cell = [tableView dequeueReusableCellWithIdentifier:LEOrderNumberCellId forIndexPath:indexPath];
        cell.model = self.orderModel;
        return cell;
    }
    
    if (indexPath.section == 1)
    {
        LEGoodsCell *cell = [tableView dequeueReusableCellWithIdentifier:LEGoodsCellId forIndexPath:indexPath];
        
        cell.model = self.orderModel.goods[indexPath.row];
        return cell;
    }
    if (indexPath.section == 2)
    {
        LEOrderTimeCell *cell = [tableView dequeueReusableCellWithIdentifier:LEOrderTimeCellId forIndexPath:indexPath];
        cell.model = self.orderModel;
        return cell;
    }else
    {
        if (indexPath.row == 0)
        {
            LEPayTypeCell *cell = [tableView dequeueReusableCellWithIdentifier:LEPayTypeCellId forIndexPath:indexPath];
            cell.model = self.orderModel;
            return cell;
        }else
        {
            LEServieStaffCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LEServieStaffCell" forIndexPath:indexPath];
            cell.model = self.orderModel;
            return cell;
        }
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 3 && indexPath.row == 1)
    {
        if (self.orderModel.service_truename) {
            [MakerTools CallPhone:self.orderModel.service_telphone];
        }else{
            LELog(@"%s---%d---指派服务人员",__func__,__LINE__);
            LESelectStaffController *select = [[LESelectStaffController alloc] init];
            select.order_id = self.orderModel.order_id;
            [self.navigationController pushViewController:select animated:YES];
        }
    }
}

@end









